﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TabFormCommon.ascx.cs" Inherits="Sagacity.NC.Form.TabFormCommon" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<script type="text/javascript" language="javascript" src="../../resources/JS/Sg.js"></script>
<script type="text/javascript" language="javascript" src="../../resources/JS/examples.js"></script>

<!--基本设置部分-->
<script language="javascript" type="text/javascript">
    var xmlDoc = null;
    var resourceId = 0;
    var selectRowRecord = null;
    var selModelId = 0;
    var treeRealValue = "",selectedValue = false;//取得树节点的真实值和是否已经查找到真实值
    var stylePageUrl = null;//定义样式表页面的访问路径
    var showForm = '<%=ShowForm %>';
    var selColumn = null;

	//显示提示浮动
	var Form$FloatText = function(value){if(value == null || value == "null")return "";return "<span title="+value+">"+value+"</span>";}
	var Form$DetailsRender = function() {
	    if(typeof HosDetailsRender != 'undefined' )
        {
            return "<img class='imgEdit' ext:qtip='表单信息' style='cursor:pointer;' src='"+((typeof editImg != "undefined")? editImg :"../resources/Images/vcard_edit.png")+"' />";
        }else
	 return "<img class='imgEdit' ext:qtip='表单信息' style='cursor:pointer;' src='"+((typeof editImg != "undefined")? editImg :"../../resources/Images/vcard_edit.png")+"' />";}
	var Form$ButtonRender = function(){ return "<input class='button' type='button' style='width:75px;height:20px;' onclick='' value='"+((typeof buttonTxt != "undefined" ) ? buttonTxt : "设置")+"' />";}
	var From$LinkRender = function(value){if(value == null || value == "null")return ""; return "<a href='#' class='styleLink' style='color:blue;'>"+value+"</a>";}

	//显示详细信息Logo
	var Form$cellClick = function (grid, rowIndex, columnIndex, e) {
	    var record = grid.getStore().getAt(rowIndex);
	    var selColumn = <%=this.ClientID %>_GridPanel1.getColumnModel().columns[columnIndex];
	    selectRowRecord = record;
	    
		var t = e.getTarget();
		<%=winForm.ClientID %>.hide();
		
		var key = eval('record.data.'+document.getElementById('<%=hidKey.ClientID %>').value);
		<%=hidKeyId.ClientID %>.setValue(key);
		
		GetXMLDoc();
		
		//自定义行选中事件
		if(typeof rowSelectedEvent != 'undefined')
		    eval(rowSelectedEvent);
		else{
		    if (t.className == 'imgEdit') {
			    Form$showForm(record);
		    }
		    else if(t.className == 'button'){
		        var showUrlTree = true;
		        //showbtnFunctionName方法由调用此用户控件的页面提供,并返回值表示是否执行下面的TreeUrl窗口的显示
		        if(typeof showbtnFunctionName != 'undefined')
		            showUrlTree = eval(showbtnFunctionName);
		        
		        if(!showUrlTree && showUrlTree != undefined)
		            return;
	            
	            var columnInfo = xmlDoc.selectSingleNode("Root/Fields/Field[@Name='"+selColumn.dataIndex+"']");
	            var url = columnInfo.getAttribute("DataSourceUrl");
    		    
	            /*-----传递主键值------*/
	            url += (((url.indexOf('?') > -1) ? "&":"?") + "KeyId="+Form$getKeyValue());
    		    
	            Form$ShowUrlTree(url,columnInfo.getAttribute("WinTitle"));
		    }
		    else if(t.className == 'styleLink'){
		        var column = <%=this.ClientID %>_GridPanel1.getColumnModel().columns[columnIndex];
		        var tempColNames = column.dataIndex.split("_");
		        var colName = tempColNames[tempColNames.length - 1];

		        var xmlNode = xmlDoc.selectSingleNode("Root/Fields/Field[@Name='"+colName+"']");
    		    
		        var keyId =eval('record.data.'+colName);
		        var styleId = xmlNode.attributes.getNamedItem("FieldStyle").text;		    
		        showFieldStyle(styleId,keyId);
		    }
		}
	}
	
	function Form$RowContentClick(e,e1,e2,e3){
	    
	}
	
	/*----------显示字段对应样式页面-----------*/
	function showFieldStyle(styleId,keyId,resourceId){
	    var urlParamters = "?styleId="+styleId+"&KeyId="+keyId;
	    var url =stylePageUrl == null ? "../Form/ResourceFieldStyle.aspx":stylePageUrl;
	    window.open(url+urlParamters,"_blank","");
	}
	
	/*-----------Button控件类型操作----------*/
	var Form$ShowUrlTree = function(url,title){
	    <%=winUrlTree.ClientID %>.autoLoad.url = url; 
	    <%=winUrlTree.ClientID %>.setTitle(title);
		<%=winUrlTree.ClientID %>.reload();
		<%=winUrlTree.ClientID %>.show();
	}
	/*----------------end----------------------*/
	
	/*--双击数据行--*/
	var Form$dbClick = function(){
	    Form$showForm(selectRowRecord);
	}
	
	function Form$showForm(record){
	    restoreComboxData();
	    /*-------showFunctionName具体使用规则请参考PersonManagement/PersonInfoList.aspx--------*/
	     //showbtnFunctionName方法由调用此用户控件的页面提供
	    if(typeof showFunctionName == "undefined"){	        
    	    <%=hidExcuteState.ClientID %>.setValue(1);
		    <%=winForm.ClientID %>.show();

	        <%=winForm.ClientID %>.setTitle("数据表单 _修改");
		    showDetailInfo(record);
		}
		else
		    eval(showFunctionName);	
		    
		    
	    if(showForm == "False"){
	        <%=winForm.ClientID %>.hide();
	    }
        winFormSetMax();
	}
      
      function SetWindoWTitleAdd(){
        <%=winForm.ClientID %>.setTitle("数据表单 _新增");
      }
      
      function GetXMLDoc(){
        if(xmlDoc != null)
          return;
        xmlDoc = Sg.xmlDocument();
        if(xmlDoc != null)
          xmlDoc.loadXML(<%=hidXML.ClientID %>.getValue());
      }
      
      /*--显示选中行的表单数据--*/
      function showDetailInfo(detail){
        GetXMLDoc();
        var editFields = xmlDoc.selectNodes("Root/Fields/Field");
        for(var i =0;i < editFields.length;i++){
          var field = editFields[i].attributes[0].text;
          try{
            var control = eval('<%=this.ClientID %>_'+field);
          }catch(e){
            continue;
          }
          var type = editFields[i].attributes[1].text;
          var value = eval("detail.data."+field);
          
          //判断数据为空的情况
          if(value == null)
             value = "";
          
          switch(type){
          
            case "DateTime":
                var date = "";
                var temp = date = eval("detail.data."+field);
                if(temp != "" && temp != undefined)
                    var date = eval("detail.data."+field+".format('Y-m-d')");
                
                eval("<%=this.ClientID %>_"+field+".setValue('"+date+"')");
                break;
            
            case "Combox":
                var items = eval("<%=this.ClientID %>_"+field).store.data.items;
                for(var j =0;j<items.length;j++ ){
                  if(items[j].data.value == value){
                    eval("<%=this.ClientID %>_"+field+".setValue('"+items[j].data.value+"')");
                    break;
                  }
                }
                break;
            
            case "Tree":
                var e = xmlDoc.selectSingleNode("Root/Fields/Field[@ControlType='Tree'][@Name='"+field+"']");

                if(e != null){
                    treeRealValue = 0;
                    treeRealValue = eval("detail.data."+field);
                    if(treeRealValue != null){
                        var text = eval("detail.data.CAPTION_"+field) == null? "" : eval("detail.data.CAPTION_"+field);
                        eval("<%=this.ClientID %>_"+field+".setValue('"+text+"')");
                        e.attributes[5].text = treeRealValue; 
                    }
                }
                break;
            case "Button":
                break;
            
            default:
                eval("<%=this.ClientID %>_"+field+".setValue('"+value+"')");
                break;
            }
            
            if(type.indexOf("Selector") > 0){
                var e = xmlDoc.selectSingleNode("Root/Fields/Field[@EnableEdit='True'][@Name='"+field+"']");

                if(e != null){
                    treeRealValue = 0;
                    treeRealValue = eval("detail.data."+field);
                    if(treeRealValue != null){
                        var text = eval("detail.data.CAPTION_"+field) == null ? "" : eval("detail.data.CAPTION_"+field);
                        eval("<%=this.ClientID %>_"+field+".setValue('"+text+"')");
                        e.attributes[5].text = treeRealValue; 
                    }
                }
            }
          }
      }
      
       /*--执行数据保存方法--*/
      function excuteSave(){
        var excuteResult = false;
        GetXMLDoc();
        if(xmlDoc != null){
            if(showForm != "False"){
                  var editFields = xmlDoc.selectNodes("Root/Fields/Field[@EnableEdit='True']");
                  for(var i =0;i < editFields.length;i++){
                    var type = editFields[i].attributes[1].text;
                    var getvalue = editFields[i].attributes[0].text;
                   
                    switch(type){
                    
                      case "DateTime":
                            var date = eval("<%=this.ClientID %>_"+getvalue).getValue();
                            if(date == ""){
                                editFields[i].attributes[5].text = "";
                            }else{
                                editFields[i].attributes[5].text = toDate(date);
                            }                            
                            break;    
                      case "Month":                  
                      case "Text":
                      case "TextArea":
                           editFields[i].attributes[5].text = eval("<%=this.ClientID %>_"+getvalue).getValue();
                           break;
                      case "Numeric":
                           editFields[i].attributes[5].text = eval("<%=this.ClientID %>_"+getvalue).value;
                           if(eval("<%=this.ClientID %>_"+getvalue).getValue() == ""){
                              editFields[i].attributes[5].text = "0";
                           }
                          break;
                      case "Tree":
                          //已在getTreeSelectValue()和showDetailInfo()的Tree类型中处理
                      case "Button":
                      case "PositionSelector":
                      case "PersonSelector":
                            break;
                      
                      default:
                           editFields[i].attributes[5].text = eval("<%=this.ClientID %>_"+getvalue).value;
                           break;
                    }
                  }
          }
          
           
          xmlDoc.selectSingleNode("Root/TableInfo").attributes[1].text = <%=hidExcuteState.ClientID %>.getValue();
          xmlDoc.selectSingleNode("Root/Fields/Field[@Name='"+xmlDoc.selectNodes("Root/TableInfo")[0].attributes[2].nodeValue+"']").attributes[5].nodeValue = <%=hidKeyId.ClientID %>.getValue();
          <%=hidXML.ClientID %>.setValue(xmlDoc.xml);

          Coolite.AjaxMethods.<%=this.ClientID %>.SubmitForm({success:function(result){
                    var temp = result.split("$");
                    if(temp[0] == 'True'){
                        <%=winForm.ClientID %>.hide();
                    }
                    Ext.example.msg('提 示',temp[1]);
                    <%=hidKeyId.ClientID %>.setValue("")
                },
                failure: function(){               
                    Ext.example.msg('提 示', '操作执行失败!');
                },
                eventMask: {
                  showMask: true,
                  msg: '正在执行...'
                }   
           });
        }
      }
      
      /*--将窗体表单中的控件的值清空（用于新增）--*/
      function clearForm(){
        GetXMLDoc();
        if(xmlDoc != null){
          var editFields = xmlDoc.selectNodes("Root/Fields/Field");
          for(var i =0;i < editFields.length;i++){
            var field = editFields[i].attributes[0].text;
            try{
                var control = eval('<%=this.ClientID %>_'+field);
            }catch(e){
                continue;
            }
            
            var type = editFields[i].attributes[1].text;
            var getvalue = editFields[i].attributes[0].text;
            switch(type){
              case "Tree":
                  eval("<%=this.ClientID %>_"+getvalue).setValue("");
                  var e = xmlDoc.selectSingleNode("Root/Fields/Field[@EnableEdit='True'][@ControlType='Tree'][@Name='"+field+"']");
                  if(e != null)
                   e.attributes[5].text = "";
                  break;
              case "Button":
                  break;
              default:
                  eval("<%=this.ClientID %>_"+getvalue).setValue("");
                  break;
            }
          }
        }
      }
      
      /*--保存当前窗体中的数据--*/
      function saveFormData(){
        if(!FormValidate()){
            Ext.Msg.alert('注意','保存时数据验证失败，请检查你的数据。');
            return;
        }
        else{
            excuteSave();
        }
      }
      
      /*--通过当前已生成的树，获取当前树控件字段的真实值--*/
      function getTreeFieldValue(text,treeNodes){
         if(typeof treeNodes == "undefined" || selectedValue == true)
            return;
         for(var i = 0 ;i < treeNodes.length;i++){
            if(treeNodes[i].text == text){
                treeRealValue = treeNodes[i].id;
                selectedValue= true;
                break;
            }
            else{
                getTreeFieldValue(text,treeNodes[i].children);
            }
         }
      }
      
      /*---------针对树形选择器-------------*/
      var partText = "";
      var selectNode = null;
      function showTreeWin(window){
        eval("<%=this.ClientID %>_"+window).show();
      }
      
      function Form$isDataType(node,btnName){
         var enable = node.attributes.dataType == 0;
         eval("<%=this.ClientID %>_btn_OK_" + btnName).setDisabled(enable);
      }
      
      function getTreeSelectValue(trigger,tree,win,title){
        var node = eval("<%=this.ClientID %>_"+tree).getSelectionModel().selNode;
        selectNode = node;
        
        if(node != null && node != "undefined")
        {
            hideTreeWin(win);
            getSelectPartText(node);
            eval("<%=this.ClientID %>_"+trigger).setValue(node.text);
            var e = xmlDoc.selectSingleNode("Root/Fields/Field[@EnableEdit='True'][@ControlType='Tree'][@Name='"+trigger+"']");
            if(e != null)
            {   
                if(parseInt(node.id) < 0)
                {
                    Ext.Msg.show({title:'注意', msg: '请选择'+title+"!", buttons:Ext.Msg.OK});
                    return;
                }
                e.attributes[5].text = node.id;
            }
        }
        else
            Ext.Msg.show({title:'注意', msg: '请选择一个节点!', buttons:Ext.Msg.OK});
      }
      
      function hideTreeWin(window){
         eval("<%=this.ClientID %>_"+window).hide();
      }

      function getSelectPartText(n) {
        if (n == selectNode) {
            partText = n.text;
        } else {
            partText = n.text + " -> " + partText;
        }
        
        if (n.parentNoden != null && n.parentNode.text != "RootNode") {
            getSelectPartText(n.parentNode);
        }
     }     
     /*-----------------end-------------------*/
     
     /*--获取列表中选中项的主键值，并依照一定的格式保存--*/
     function getGridSelects(){
        var selects = <%=GridPanel1.ClientID %>.getSelectionModel().selections.items;
        <%=hidSelects.ClientID %>.setValue("");
        for(var s = 0;s < selects.length;s++){
            <%=hidSelects.ClientID %>.setValue(<%=hidSelects.ClientID %>.getValue()+selects[s].id+"$");
        }
     }

     /*--删除数据--*/
     function DelData(){
          var selects = <%=GridPanel1.ClientID %>.getSelectionModel().selections.items.length;
          if(selects == 0){
             Ext.Msg.alert('注意','请选择需要操作的数据。');
             return;
          }
    
          //提供验证数据的方法，如果验证不通过，则不能被删除，注意：validateDelData验证的方法由调用此控件的页面提供
          var validate = true;
          if(typeof validateDelData != 'undefined')          
               validate = eval("validateDelData(<%=GridPanel1.ClientID %>.getSelectionModel().selections.items)");
          
          //referenceDelData引用的删除方法由调用此用户控件的页面提供
          if(typeof referenceDelData != 'undefined'){
             eval("referenceDelData(<%=GridPanel1.ClientID %>.getSelectionModel().selections)");//删除成功之后，需要调用Form$ReloadData()方法刷新数据
             validate = false;//屏蔽掉下边的删除方法，只能执行引用的删除方法
          }
          
            <%=winForm.ClientID %>.hide();
            if(validate == true){
                Ext.MessageBox.confirm('注意', '确认是否删除？', function(btn) {
                    if (btn=="yes") {
                        getGridSelects();
                        
                        <%=hidExcuteState.ClientID %>.setValue(2);
                        excuteSave();
                        
                        if ( typeof deleteedEvent != 'undefined')
                            eval(deleteedEvent);
                    }
                });
            }
     }
     
     /*--新增数据--*/
     function NewData(){
        
        //showFunctionAdd方法由调用此用户控件的页面提供
        if(typeof showFunctionAdd != 'undefined' )
        {
            eval(showFunctionAdd);
            return;
        }
        
        <%=winForm.ClientID %>.show();
        SetWindoWTitleAdd();
        <%=this.ClientID %>_btnAdd.setVisible(true);
        //<%=this.ClientID %>_btnSave.setVisible(true);
        <%=hidExcuteState.ClientID %>.setValue(0);
        clearForm();
     }
     
     /*--表单验证--*/
     function FormValidate(){
        GetXMLDoc();
        var editFields = xmlDoc.selectNodes("Root/Fields/Field[@EnableEdit='True']");
        var validate = true;
        for(var i = 0 ;i < editFields.length;i++){
            if(!eval("<%=this.ClientID %>_"+editFields[i].attributes[0].text).validate())
            {
                validate = false;
                break;
            }
        }
        return validate;
     }
     
     /*--隐藏表单窗体--*/
     function hidWinForm(){
        <%=winForm.ClientID %>.hide();
     }
     
     var tempCounter = 0 ;
     function winFormSetMax(){
        if(tempCounter == 0){
            <%=winForm.ClientID %>.maximize();
            tempCounter ++;
        }
     }
     
     function triggerValue(fieldName,index,otherEvent){
         if(index == 0){            
             GetXMLDoc();
             var field = xmlDoc.selectSingleNode("Root/Fields/Field[@EnableEdit='True'][@Name='"+fieldName+"']");
             eval("<%=this.ClientID %>_"+fieldName+".setValue('')");
             field.attributes[5].text = '';
         }else{
            eval(otherEvent);
         }
     }
     
     //打开附件管理器
     function filesManage(){
        var reValue = window.showModalDialog("../form/ResourceAttachment.aspx?ResourceId=<%=ResourceId %>",
        "附件管理","dialogWidth:590px;dialogHeight:320px;scroll:no;status:no;toolbar:no;menubar:no;resizable:yes;");
     }
</script>

<!--人员选择和岗位选择-->
<script type="text/javascript" language="javascript">
    function Form$GetSelectorValue(type,fieldName){
    
        var reValue = window.showModalDialog("../Form/Selector.aspx?type="+type,
            '',"dialogWidth:700px;dialogHeight:380px;scroll:no;status:no;toolbar:no;menubar:no;resizable:no;");
        if(reValue == null || reValue == 'undefined')
            return;
        var temps = reValue.split(";")[0].split("$");
        var e = xmlDoc.selectSingleNode("Root/Fields/Field[@EnableEdit='True'][@Name='"+fieldName+"']");
        eval("<%=this.ClientID %>_"+fieldName+".setValue('"+temps[1]+"')");
        e.attributes[5].text = temps[0];
    }
</script>

<!--表单筛选方案设置部分-->
<script type="text/javascript" language="javascript">
    var reValue = null;
    function showModelWindow() {
        var reValue = window.showModalDialog("../form/FilterModels.aspx?ResourceId=<%=ResourceId %>",
        "筛选方案设置","dialogWidth:590px;dialogHeight:380px;scroll:no;status:no;toolbar:no;menubar:no;resizable:yes;");
        
        if (reValue != null) {
            Coolite.AjaxMethods.<%=this.ClientID %>.GetModelFilterResult(reValue);
            selModelId = reValue;
        }
    }
</script>

<!--设置JS接口方法-->
<script language="javascript" type="text/javascript">
    /*----------关闭UrlTree-----------*/
    function Form$colseWinUrlTree(){
        <%=winUrlTree.ClientID %>.hide();
    }
    
    /*----------在当前选中行中获取指定列的值，未指定时返回主键字段的值-----------*/
    function Form$getKeyValue(key){
        if(key == undefined)
            return <%=hidKeyId.ClientID %>.getValue();
         else{
                var value = eval("selectRowRecord.data."+key);
                if(value == 'undefined')
                    return '';
                 else
                    return value;
            }
    }
    
    /*----------显示消息------*/
    function Form$ShowResult(result,msg){
        if(result == true)
            Ext.Msg.alert('注意','执行成功！');
        else if(result == false)
            Ext.Msg.alert('注意','执行失败！');
        else
            Ext.Msg.alert('注意',msg);
    }
    
    /*----------重新加载数据-------*/
    function Form$ReloadData(){
        <%=GridPanel1.ClientID %>.reload();
    }
    
    /*----------加载资源的过滤条件------*/
    function Form$SetFilters(value){
        <%=hidInterfaceFilters.ClientID %>.setValue(value);
    }
    
    /*----------取得资源编号----------*/
    function Form$GetResourceId(){
        GetXMLDoc();
        var tabInfo =  xmlDoc.selectSingleNode("Root/TableInfo");
        return tabInfo.attributes.getNamedItem("Resource").text;
    }
</script>

<!--Ajax加载树-->
<script type="text/javascript">
    function Form$nodeLoad(node) {
        Coolite.AjaxMethods.<%=this.ID %>.NodeLoad(node.id,node.attributes.fieldId,node.attributes.nodeClickHandler, {
            success: function(result) {
                var data = eval("(" + result + ")");
                node.loadNodes(data);
            },

            failure: function(errorMsg) {
                Ext.Msg.alert('节点加载失败',errorMsg);
            }
        });
    }
</script>

<!--日志窗口-->
<script type="text/javascript" language="javascript">
    var ShowWindow = function()
     {             
        var resourceId =<%=hidResourceId.ClientID %>.getValue();
        <%=winLogForm.ClientID %>.show();
        <%=winLogForm.ClientID %>.autoLoad.url = "../../sys/Log/LogDetail.aspx?resourceId="+resourceId+"&keyId="+Form$getKeyValue();
        <%=winLogForm.ClientID %> .autoLoad.nocache = true;
        <%=winLogForm.ClientID %>.reload();
     }
</script>

<!--右键菜单设置-->
<script language="javascript" type="text/javascript">
    function showObserve(xy,rowIndex){
        try{
            if(rowIndex >= 0){
                <%=MenuView1.ClientID %>.show();
            }else{
                <%=MenuView1.ClientID %>.hide();
            }
        }catch(e){}
        
        try{
        
            <%=RowContextMenu.ClientID  %>.showAt(xy);
            var record = <%=GridPanel1.ClientID %>.getStore().getAt(rowIndex);
            var key = eval('record.data.'+document.getElementById('<%=hidKey.ClientID %>').value);
		    <%=hidKeyId.ClientID %>.setValue(key);
        }catch(e){}
    }
    
    function addObserve(viewId){
        Coolite.AjaxMethods.<%=this.ClientID %>.AddObserve(viewId,Form$getKeyValue(),{
            success:function(result){
                var temp = result.split("$");
                if(temp[1] == "True"){
                    Ext.Msg.alert("注意","添加成功");
                }else{
                    Ext.Msg.alert("注意",temp[0]);
                }
            },
            failure:function(errormsg){
                Ext.Msg.alert("注意",errormsg);
            }
        });
    }
</script>

<!--设置关联字段信息-->
<script language="javascript" type="text/javascript" >
    var cbStores = new Array();
    
    //取得关联字段的值
    function getAssoFieldValues(Name){
        GetXMLDoc();
        
        var assoField = xmlDoc.selectSingleNode("Root/Fields/Field[@Name='"+Name+"'][@AssoParam]");
        var assoInfo = eval(assoField.getAttribute("AssoParam"));
        var selectedValue = "";
        if(assoField.getAttribute("ControlType") == "Tree")
            selectedValue = assoField.getAttribute("Value");
        else if(assoField.getAttribute("ControlType") == "Combox")
            selectedValue = eval('<%=this.ClientID %>_'+ Name).getValue();
        
        for(var i = 0; i < assoInfo.length ;i++){
            var fieldId = assoInfo[i]["FieldId"];
            var fieldName = assoInfo[i]["FieldName"];
            var paramName =  assoInfo[i]["ParamName"];
            
            var field = xmlDoc.selectSingleNode("Root/Fields/Field[@EnableEdit='True'][@Name='"+fieldName+"']");
            var controlType = field.getAttribute("ControlType");            
            
            Coolite.AjaxMethods.<%=this.ClientID %>.GetFieldAssoDataInfo(controlType,fieldId,paramName,selectedValue,{
                success:function(result){
                    SetAssoFieldValue(result);
                },
                failure:function(errormsg){
                    Ext.Msg.alert("注意",errormsg);
                }
            });
        }
    }
    
    //设置关联字段控件值
    function SetAssoFieldValue(values){    
        var results = values.split("$");
        values = eval(results[0]);
        var orgData = eval("[{"+results[1]+"}]")[0];
        controlType = orgData.controlType;
        var fieldName = orgData.fieldName;
        control = controlType == "Combox" ? eval('<%=this.ClientID %>_'+ fieldName) : eval('<%=this.ClientID %>_Tree_'+ fieldName);
        
        if(controlType == "Tree"){
            eval('<%=this.ClientID %>_'+ fieldName).enable();
            eval('<%=this.ClientID %>_'+ fieldName).setReadOnly(false);
            if(control.root.loaded == false){
                control.root.rootVisible = false;
            }
            control.root.loaded = true;
            control.root.removeChildren();
            appendChild(values,control.root,fieldName);
        }else if(controlType == "Combox"){
            
            /*-----------------保存重设前的Combox的数据，以便重设---------------------*/
            var hasRecored = false;
            for(var i = 0;i< cbStores.length;i++){
                if(cbStores[0].FieldName == fieldName){
                    hasRecored = true;
                }
            }
            
            if(!hasRecored){
                var store = new Object();
                store.FieldName = fieldName;
                store.items = control.getStore().data.items;
                cbStores[cbStores.length] = store;
            }
            /*----------------------*/
            
            control.enable();
            control.getStore().removeAll();
            control.setValue('');
            
            for(var i = 0 ;i < values.length;i++){                
                control.addItem(values[i]["CAPTION"],values[i]["ID"]);
            }
        }
    }
    
      function appendChild(data,node,fieldName){
          for(var i = 0;i < data.length ;i++){ 
             var showChecked = typeof data[i].CHECKED != 'undefined';
             var checked = data[i].CHECKED == "true";
             
             var n = null;
             
             //当前节点的IsData属性值是否为true，判断是否生成树控件节点的checkbox
             if(showChecked)
                n = new Ext.tree.TreeNode({
                    id:data[i].ID,
                    checked:checked,
                    text:data[i].CAPTION
                });
             else
                n = new Ext.tree.TreeNode({
                    id:data[i].ID,
                    text:data[i].CAPTION,
                    dataType:data[i].ISDATA,
                    listeners:{
                        "click":function(node,event){
                            Form$isDataType(this,fieldName);
                        }
                    }
                });
                
             node.appendChild(n);
             appendChild(data[i]["CHILDREN"],n,fieldName);
          }
       }
       
       function restoreComboxData(){
            for(var i = 0 ;i < cbStores.length;i++){
                var control = eval('<%=this.ClientID %>_'+ cbStores[i].FieldName);
                control.getStore().removeAll();
                control.disable();
                for(var j =0;j < cbStores[i].items.length;j++){  
                    var value = cbStores[i].items[j].data;                  
                    control.addItem(value.text,value.value);                    
                }
            }
       }
</script>

<!--执行SQL方案-->
<script language="javascript" type="text/javascript">
    function excuteSqlCases(){
        var exsqlcases = "";
        var sqlcases = document.getElementById('<%=hidSqlCases.ClientID %>').value.split(',');
        for(var i = 0 ;i < sqlcases.length;i++){
            var temp = eval("<%=this.ClientID %>_ckSqlCase"+sqlcases[i]);
            if(temp.checked){
                exsqlcases += sqlcases[i]+",";
            }   
        }
        
        Coolite.AjaxMethods.<%=this.ClientID %>.ExcuteSqlCases(exsqlcases,{
            success:function(result){
                if(result == ""){
                    Ext.Msg.alert("注意","方案执行成功！");
                }else{
                    Ext.Msg.alert("注意",result);
                }
            },failure:function(msg){
                Ext.Msg.alert(msg);
            },eventMask: {
                  showMask: true,
                  msg: '正在执行...'
           },timeout:60000
        });
    }
</script>

<!--附件管理器-->
<script language="javascript" type="text/javascript">
    function filesAttachment(){
        var objId = Form$getKeyValue();
        if(objId == ""){
            Ext.Msg.alert("注意","请选中附件关联的数据！");
            return;
        }
        var reValue = window.showModalDialog("../form/ResourceAttachment.aspx?ResourceId=<%=ResourceId %>&ObjId="+objId,
        "","dialogWidth:590px;dialogHeight:380px;scroll:no;status:yes;toolbar:no;menubar:no;resizable:yes;");
    }
</script>

<!--资源数据查询配置--->
<script language="javascript" type="text/javascript">
    function getDataQueryCnf(){
        Coolite.AjaxMethods.<%=this.ClientID %>.GetDataQueryCnf({success:function(result){
            //类型为1时，为资源数据
            var url = "DataType="+1+"&RID="+Form$GetResourceId()+"&FilterModelId="+selModelId+"&"+result;
            window.open('../Report/SimpleReport.aspx?'+url,'_blank','');
        }});
    }
</script>

<asp:HiddenField ID="hidKey" runat="server" />
<asp:HiddenField ID="hidPersonObserveRId" runat="server" Value="79" />
<asp:HiddenField ID="hidPersonObserveDetailRId" runat="server" Value="88" />
<asp:HiddenField ID="hidSqlCases" runat="server" />

<ext:Hidden ID="hidKeyId" runat="server" />
<ext:Hidden ID="hidXML" runat="server" />
<ext:Hidden ID="hidHasDetailColumn" runat="server" />
<ext:Hidden ID="hidExcuteState" runat="server" />
<ext:Hidden ID="hidSelects" runat="server" />
<ext:Hidden ID="hidResourceId" runat="server" />

<%--加载资源的过滤条件,针对Store1的Store_Refresh设计，必须满足格式：f1$t1$v1;f2$t2$v2;--%>
<ext:Hidden ID="hidInterfaceFilters" runat="server" />

<ext:Store ID="Store1" runat="server" OnRefreshData="Store_Refresh" OnSubmitData="Store1_Submit">
</ext:Store>
<ext:BorderLayout ID="BorderLayout1" runat="server">
    <North >
        <ext:Toolbar ID="projectToolbar"  Visible="true" AutoHeight="true" Height="25" runat="server">
            <Items>
                <ext:Button ID="btnExport" runat="server" Visible="false" AutoPostBack="true" OnClick="ToExcel" Text="Excel导出" Icon="PageExcel">
                </ext:Button>
                <ext:Button ID="btnImport" runat="server" Visible="false"  Text="数据导入" Icon="DvdGo">
                    <Listeners>
                        <Click Handler="javascript:#{winImport}.show();" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="btnAdd" runat="server" Visible="false" Icon="Add" Text="新增">
                    <Listeners>
                        <Click Handler="javascript:NewData();winFormSetMax();" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="btnDel" runat="server" Visible="false" Icon="Delete" Text="删除">
                    <Listeners>
                        <Click Handler="javascript:DelData();" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="btnSave" runat="server" Visible="false" Enabled="false" Text="保存" Icon="Disk">
                    <Listeners>
                        <Click Handler="javascript:#{GridPanel1}.submitData(false);" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="btnRefresh" runat="server" Visible="false" Text="刷新" Icon="ArrowRotateAnticlockwise">
                    <Listeners>
                        <Click Handler="javascript:#{GridPanel1}.reload();" />
                    </Listeners>
                </ext:Button>
                <ext:Button ID="btnFilterModle" Visible="false" Icon="ApplicationFormMagnify" Text="筛选方案"
                    runat="server">
                    <Listeners>
                        <Click Handler="javascript:showModelWindow();" />
                    </Listeners>
                </ext:Button>
                <ext:ToolbarButton ID="btnAsso" runat="server" Visible="false" Text="关联操作" Icon="LinkEdit">
                    <Menu>
                        <ext:Menu ID="Menu1" runat="server">
                            <Items>
                                <ext:MenuItem ID="MenuLogInfo" runat="server" Enabled="true" Visible="true" Icon="UserAlert"
                                    Text="日志信息">
                                    <Listeners>
                                        <Click Handler="javascript:ShowWindow();" />
                                    </Listeners>
                                </ext:MenuItem>
                                <ext:MenuItem ID="MenuSelfUpdate" Text="自动更新" Visible="true" AllowDomMove="true" runat="server"
                                    Icon="TableGo">
                                    <Listeners>
                                        <Click Handler="#{winSqlForm}.show();" />
                                    </Listeners>
                                </ext:MenuItem>
                                <ext:MenuItem ID="MenuDataSel" Text="数据检查" Visible="true" AllowDomMove="true" runat="server"
                                    Icon="DatabaseGear">
                                </ext:MenuItem>
                                <ext:MenuItem ID="MenuFile" Text="附件管理" Visible="true" Icon="Film" AllowDomMove="true" runat="server">
                                    <Listeners>
                                        <Click Handler="javascript:filesAttachment();" />
                                    </Listeners>
                                </ext:MenuItem>
                                <ext:MenuItem ID="MenuBizInfo" Text="业务单关联信息" Visible="true" Icon="Bin" runat="server" AllowDomMove="true">
                                </ext:MenuItem>
                                <ext:MenuItem ID="MenuReport" Text="单一报表" Visible="true" Icon="Report" runat="server" AllowDomMove="true">   
                                    <Listeners>
                                        <Click Handler="javascript:getDataQueryCnf();" />
                                    </Listeners>                                 
                                </ext:MenuItem>
                            </Items>
                        </ext:Menu>
                    </Menu>
                </ext:ToolbarButton>
            </Items>
        </ext:Toolbar>
    </North>
    <Center>
        <ext:Panel ID="Panel4" runat="server" Height="290" Header="false">
            <Body>
                <ext:FitLayout ID="FitLayout2" runat="server">
                    <ext:GridPanel ID="GridPanel1" TrackMouseOver="true" runat="server" StoreID="Store1"
                        Height="300" Border="false">
                        <BottomBar>
                            <ext:PagingToolbar ID="PagingToolBar1" runat="server" PageSize="20" StoreID="Store1">
                            </ext:PagingToolbar>
                        </BottomBar>
                        <SelectionModel>
                            <ext:RowSelectionModel SingleSelect="true" Visible="true"></ext:RowSelectionModel>
                        </SelectionModel>
                        <Listeners>
                            <CellClick Fn="Form$cellClick" />
                            <RowDblClick Fn="Form$dbClick" /> 
                            <RowContextMenu Handler="this.getSelectionModel().selectRow(rowIndex);e.preventDefault();showObserve(e.getXY(),rowIndex)" />
                        </Listeners>                                
                        <LoadMask ShowMask="true" Msg="正在加载数据..." />
                        <Plugins>
                            <ext:GridFilters ID="GridFilters1" runat="server" FiltersText="过滤">
                            </ext:GridFilters>
                        </Plugins>
                        <KeyMap>
                            <ext:KeyBinding>
                                <Keys>
                                    <ext:Key Code="DELETE" />
                                </Keys>
                                <Listeners>
                                    <Event Handler="javascript:DelData();" />
                                </Listeners>
                            </ext:KeyBinding>
                        </KeyMap>
                    </ext:GridPanel>
                </ext:FitLayout>
            </Body>
        </ext:Panel>
    </Center>
</ext:BorderLayout>

<ext:Menu ID="RowContextMenu" Visible="true" runat="server">
    <Items>
        <ext:MenuItem ID="MenuView1" Text="加入观察窗" Visible="true" AllowDomMove="true" runat="server" Icon="UserB">
            <Menu>
                <ext:Menu ID="MenuAddObserve" runat="server">
                </ext:Menu>
            </Menu>
        </ext:MenuItem>
    </Items>
</ext:Menu>

<ext:Window ID="winImport" AutoHeight="true" Title="导入数据" Width="380" Height="45"
    Modal="true" Collapsible="true" ShowOnLoad="false" runat="server">
    <Body>
        <table>
            <tr>
                <td>
                    <asp:FileUpload ID="ulImport" runat="server" Width="300" Height="20" />
                </td>
                <td>
                    <ext:Button ID="btnUp" Icon="ApplicationFormAdd" Text="确定" runat="server">
                        <Listeners>
                            <Click Handler="#{winImport}.hide();" />
                        </Listeners>
                        <AjaxEvents>
                            <Click OnEvent="UpImport">
                                <EventMask ShowMask="true" Msg="正在导入数据..." />
                            </Click>
                        </AjaxEvents>
                    </ext:Button>
                </td>
            </tr>
        </table>
    </Body>
</ext:Window>

<ext:Window ID="winSqlForm" ShowOnLoad="true" Title="SQL执行方案" Resizable="false" ButtonAlign="Center" Maximizable="false" runat="server" Width="500">
    <Body>
    <table style="width:100%;">
        <tr>
            <td style="width:100%;" colspan="2">
            <table id="tbSqlCase" runat="server">            
        </table>
            </td>
        </tr>
        <tr>
            <td align="right">
                <ext:Button ID="btnSqlExcute" runat="server" Icon="HtmlGo"  Text="执 行">
                    <Listeners>
                        <Click Handler="excuteSqlCases();#{winSqlForm}.hide();" />
                    </Listeners>
                </ext:Button>
            </td>
            <td>
                <ext:Button ID="btnCancelSql" runat="server" Icon="Cancel" Text="取 消">
                    <Listeners>
                        <Click Handler="#{winSqlForm}.hide();" />
                    </Listeners>    
                </ext:Button>
            </td>
        </tr>
    </table>
    </Body>
</ext:Window>

<ext:Window ID="winForm" ShowOnLoad="false" Title="数据表单" Resizable="false" ButtonAlign="Center" Maximizable="true"
    runat="server" Width="700">
    <Body>
        <asp:Panel ID="pnlForm" TabIndex="10" runat="server">
        </asp:Panel>
    </Body>
</ext:Window>

<ext:Window ID="winUrlTree" runat="server" ShowOnLoad="false" Collapsible="true" Height="400" Modal="true" Width="320" Resizable="false">
    <AutoLoad NoCache="true" Mode="IFrame" ShowMask="true" MaskMsg="正在加载...." Url=""></AutoLoad>    
</ext:Window>

<ext:Window ID="winLogForm" ShowOnLoad="false" Maximizable="true" Title="日志信息" Icon="Wand"
    Modal="true" runat="server" Height="250" Width="700">
    <AutoLoad Url="" Mode="IFrame">
    </AutoLoad>
    <Listeners>
        <Activate Handler="#{winLogForm}.maximize();" />
    </Listeners>
</ext:Window>

<asp:Panel ID="otherContent" runat="server">
</asp:Panel>